﻿Imports Microsoft.VisualBasic
Imports System
Imports System.Data
Imports System.Configuration
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Imports System.Collections.Generic
Imports Microsoft.Practices.EnterpriseLibrary.Data
Imports Microsoft.Practices.EnterpriseLibrary.ExceptionHandling
Imports System.Data.Common

Public Class UserDetails
#Region "Constants"
    Protected Const _udID As String = "udID"
    Protected Const _UserID As String = "UserID"
    Protected Const _FirstName As String = "FirstName"
    Protected Const _LastName As String = "LastName"
    Protected Const _DoH As String = "DateOfHire"
    Protected Const _TermDate As String = "TerminationDate"
    Protected Const _ShiftID As String = "ShiftID"
#End Region
#Region "Private"
    Private Shared intudID As Integer
    Private Shared intUserID As Integer
    Private Shared intShiftID As Integer
    Private Shared strFirstName As String
    Private Shared strLastName As String
    Private Shared dtDateOfHire As Date
    Private Shared dtTerminationDate As Date

    Private Shared blLoggedIn As Boolean = False
    Private Shared el As New errorLog
#End Region
#Region "Public"
    Public Property LoggedIn() As Boolean
        Get
            Return blLoggedIn
        End Get
        Set(ByVal value As Boolean)
            blLoggedIn = value
        End Set
    End Property
    Public Property UserDetailID() As Integer
        Get
            Return intudID
        End Get
        Set(ByVal value As Integer)
            intudID = value
        End Set
    End Property
    Public Property UserID() As Integer
        Get
            Return intUserID
        End Get
        Set(ByVal value As Integer)
            intUserID = value
        End Set
    End Property
    Public Property ShiftID() As Integer
        Get
            Return intShiftID
        End Get
        Set(ByVal value As Integer)
            intShiftID = value
        End Set
    End Property
    Public Property FirstName() As String
        Get
            Return strFirstName
        End Get
        Set(ByVal value As String)
            strFirstName = value
        End Set
    End Property
    Public Property Lastname() As String
        Get
            Return strLastName
        End Get
        Set(ByVal value As String)
            strLastName = value
        End Set
    End Property
    Public Property DateOfHire() As Date
        Get
            Return dtDateOfHire
        End Get
        Set(ByVal value As Date)
            dtDateOfHire = value
        End Set
    End Property
    Public Property TerminationDate() As Date
        Get
            Return dtTerminationDate
        End Get
        Set(ByVal value As Date)
            dtTerminationDate = value
        End Set
    End Property
#End Region
    Public Function LoadUserDetailsByUserID() As Boolean
        Dim _blFound = False
        Dim db As Database = DbStoreFactory.CreateDatabase
        Dim cmd As DbCommand = DirectCast(Nothing, DbCommand)
        Dim reader As IDataReader = Nothing

        Try
            cmd = db.GetStoredProcCommand("GetUserDetailsByUserID")
            db.DiscoverParameters(cmd)
            cmd.Parameters("@intUserID").Value = intUserID

            reader = db.ExecuteReader(cmd)

            Do While (reader.Read)
                intUserID = Convert.ToInt16(reader(_UserID))
                intudID = reader(_udID).ToString
                strFirstName = reader(_FirstName).ToString
                strLastName = reader(_LastName).ToString
                dtDateOfHire = Convert.ToDateTime(reader(_DoH).ToString)
                If Not IsDBNull(reader(_TermDate)) Then
                    dtTerminationDate = Convert.ToDateTime(reader(_TermDate))
                End If
                intShiftID = Convert.ToInt16(reader(_ShiftID))

                _blFound = True
            Loop

        Catch ex As Exception
            el.CatchError(ex)
        Finally
            If Not (cmd Is Nothing) Then
                cmd.Dispose()
            End If
            If Not (reader Is Nothing) Then
                reader.Close()
            End If
        End Try

        Return _blFound
    End Function
End Class
